package com.quanyan.place.web;

import com.quanyan.api.APIResponse;
import com.quanyan.place.entity.ReqAdminUserVo;
import com.quanyan.place.service.PlaceAuthUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created by Administrator on 2016/6/14.
 * 用户授权模块
 */
@RestController
@RequestMapping("/admin/api/place/user/auth")
public class PlaceAuthUserController {
    @Autowired
    PlaceAuthUserService placeAuthUserService;

    /**
     * 根据城市ID筛选对应的用户
     * @param reqAdminUserVo
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "/getUserByCityID" ,method = RequestMethod.POST,produces = {"application/json; charset=UTF-8"})
    @ResponseBody
    public APIResponse getUserByCityID(@RequestBody @Valid ReqAdminUserVo reqAdminUserVo,BindingResult bindingResult){
        return APIResponse.returnSuccess(placeAuthUserService.getAdminUserByCity(reqAdminUserVo));
    }

    /**
     * 插入场馆用户授权记录
     * @param reqAdminUserVo
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "/insertAuthUser" ,method = RequestMethod.POST,produces = {"application/json; charset=UTF-8"})
    @ResponseBody
    public APIResponse insertAuthUser(@RequestBody @Valid ReqAdminUserVo reqAdminUserVo,BindingResult bindingResult){
        return APIResponse.returnSuccess(placeAuthUserService.insertAuthUser(reqAdminUserVo));
    }

    /**
     * 根据场馆id查询用户详情
     * @param reqAdminUserVo
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "/getAdminUserAuthByPlaceId" ,method = RequestMethod.POST,produces = {"application/json; charset=UTF-8"})
    @ResponseBody
    public APIResponse getAdminUserAuthByPlaceId(@RequestBody @Valid ReqAdminUserVo reqAdminUserVo,BindingResult bindingResult){
        return APIResponse.returnSuccess(placeAuthUserService.getAdminUserAuthByPlaceId(reqAdminUserVo.getPlaceId()));
    }


    /**
     * 删除（取消授权）
     * @param reqAdminUserVo
     * @param bindingResult
     * @return
     */
    @RequestMapping(value = "/deleteAdminUserAuthByPlaceIdAndUserId" ,method = RequestMethod.POST,produces = {"application/json; charset=UTF-8"})
    @ResponseBody
    public APIResponse deleteAdminUserAuthByPlaceIdAndUserId(@RequestBody @Valid ReqAdminUserVo reqAdminUserVo,BindingResult bindingResult){
        return APIResponse.returnSuccess(placeAuthUserService.deleteAdminUserAuthByPlaceIdAndUserId(reqAdminUserVo));
    }
}
